using ReflectionStudio.Core.Events;
using System.Data;
namespace WPFExcelReport
{
    public partial class VBABEW
    {
        public static readonly VBABEW SVWB = new VBABEW();

        string LastOrder = "";
        int BBLFDNR = 1;
        string BBBELEG = "";
        public void NWBBEW(DataRow dwBB, string BEWBS, string _RUNID)
        { 
            if (dwBB == null)
                return;
            dwData = TBMain.NewRow();
            SetUpNewRow(ref dwData);
            string _time = "";
            string _date = "";
            Helpers.Helper.GetTime(ref _date, ref _time);
            if (BEWBS == "20" || BEWBS == "21")
            {

                string order = dwBB["BMBAUMKRS"].ToString() + dwBB["BMBAUMLFD"].ToString();
                if (LastOrder == order)
                {
                    BBLFDNR++;
                }
                else
                {
                    LastOrder = order; 
                    BBBELEG = VSDDAT.SD22.GETNEXT("0022", "  ", "BEWEGUNG",2); 
                    BBLFDNR = 1;
                }
            }
            else
            {
                BBBELEG = VSDDAT.SD22.GETNEXT("0022", "  ", "BEWEGUNG", 2);
                BBLFDNR = 1;
            }

            switch (BEWBS)
            {
                case "20":
                    #region===20=
                    dwData["BBBELEG"] = BBBELEG;
                    dwData["BBLFDNR"] = BBLFDNR;
                    dwData["BBBS"] = "20";
                    dwData["BBLO"] =  dwBB["BMLO"];
                    dwData["BBLB"] = dwBB["BMLB"];
                    dwData["BBLPLATZ"] = dwBB["BMLP"];  
                    dwData["BBFC"] = "BB03    ";
                    dwData["BBMTR"] = dwBB["BMISTLG"];
                    dwData["BBAUFTYP"] = "V";
                    dwData["BBAUFKRS"] = dwBB["BMAUFKRS"];
                    dwData["BBAUFLFD"] = dwBB["BMAUFLFD"];
                    dwData["BBAUFPOS"] = dwBB["BMAUFPOS"];
                    #endregion
                    break;
                case "21":
                  #region===21=
                    dwData["BBBELEG"] = BBBELEG;
                    dwData["BBLFDNR"] = BBLFDNR;
                    dwData["BBBS"] = "21";
                    dwData["BBLO"] =  dwBB["BMLO"];
                    dwData["BBLB"] = dwBB["BMLB"];
                    dwData["BBLPLATZ"] = dwBB["BMLP"];  
                    dwData["BBFC"] = "BB03    ";
                    dwData["BBMTR"] = dwBB["BMISTLG"];
                    dwData["BBAUFTYP"] = "V";
                    dwData["BBAUFKRS"] = dwBB["BMAUFKRS"];
                    dwData["BBAUFLFD"] = dwBB["BMAUFLFD"];
                    dwData["BBAUFPOS"] = dwBB["BMAUFPOS"];
                    #endregion
                    break;
                case "61":
                    #region===61=
                    dwData["BBBELEG"] = BBBELEG;
                    dwData["BBLFDNR"] = BBLFDNR;
                    dwData["BBBS"] = "20";
                    dwData["BBLO"] = dwBB["BMLO"];
                    dwData["BBLB"] = dwBB["BMLB"];
                    dwData["BBLPLATZ"] = dwBB["BMLP"];
                    dwData["BBFC"] = "BB03    ";
                    dwData["BBMTR"] = dwBB["BMISTLG"];
                    dwData["BBAUFTYP"] = "V";
                    dwData["BBAUFKRS"] = dwBB["BMAUFKRS"];
                    dwData["BBAUFLFD"] = dwBB["BMAUFLFD"];
                    dwData["BBAUFPOS"] = dwBB["BMAUFPOS"];
                    #endregion
                    break;
                case "62":
                    #region===62=
                    dwData["BBBELEG"] = BBBELEG;
                    dwData["BBLFDNR"] = BBLFDNR;
                    dwData["BBBS"] = "21";
                    dwData["BBLO"] = dwBB["BMLO"];
                    dwData["BBLB"] = dwBB["BMLB"];
                    dwData["BBLPLATZ"] = dwBB["BMLP"];
                    dwData["BBFC"] = "BB03    ";
                    dwData["BBMTR"] = dwBB["BMISTLG"];
                    dwData["BBAUFTYP"] = "V";
                    dwData["BBAUFKRS"] = dwBB["BMAUFKRS"];
                    dwData["BBAUFLFD"] = dwBB["BMAUFLFD"];
                    dwData["BBAUFPOS"] = dwBB["BMAUFPOS"];
                    #endregion
                    break;
                case "36":                    
                    dwData["BBBELEG"] = BBBELEG;
                    dwData["BBLFDNR"] = BBLFDNR;
                    dwData["BBBS"] = "21";
                    dwData["BBLO"] = dwBB["BMLO"];
                    dwData["BBLB"] = dwBB["BMLB"];
                    dwData["BBLPLATZ"] = dwBB["BMLP"];
                    dwData["BBFC"] = "BB03    ";
                    dwData["BBMTR"] =Helpers.Helper.RoundX (System.Convert.ToDouble( dwBB["BMSOLLLG"].ToString())-System.Convert.ToDouble( dwBB["BMRESTLG"].ToString()),1);
                    break;
            }
        
            dwData["BBJJJJ"] = year;

            dwData["BBKART"] = dwBB["BMKART"];
            dwData["BBKVAR"] = dwBB["BMKVAR"];
            dwData["BBKFARBE"] = dwBB["BMFARBE"];

            dwData["BBBAUMKRS"] = dwBB["BMBAUMKRS"];
            dwData["BBBAUMLFD"] = dwBB["BMBAUMLFD"];
            dwData["BBAUFBKZ"] = dwBB["BMAUFBKZ"];
            dwData["BBKOLLINR"] = dwBB["BMKOLLINR"];
            dwData["BBKETTTYP"] = dwBB["BMKETTTYP"];
            dwData["BBPARTIE"] = dwBB["BMPARTIE"];           
            dwData["BBWERTDAT"] = _date; 
            dwData["BBBUCHDAT"] = _date;
            dwData["BBBUCHZEIT"] = _time;
            dwData["BBBUCHBEN"] = app.User; 
            InsertBABEW(dwData, app.company); 
        }
    }

}
